<?php
require_once('internal/IModule.interface.php');

class Config implements IModule {
	private $module;
	public $sections, $customTitle;

	function __construct($engine=null) {
		$module = trim($_GET['module'])?trim($_GET['module']):'';
		global $lang, $mae, $db;

		$path = checkIfExists($module);
		if (!$path) error('admin/errors/nomodule');

		if (isset($lang[$module]['name'])) $this->customTitle = $lang[$module]['name'];
		else {
			$db->modeNum();
			$q = $db->select('modules', 'fullname', array(
				"shortname='$module'"
			));
			$this->customTitle = $q->fields[0];
		}

		if (file_exists($path.'engine.php')) require_once($path.'engine.php');
		else require_once($path.'module.php');
		$this->engine = $engine;
		$this->module = new $module($this->engine);
		
		
		/*$this->sections = array_merge(isset($this->module->sections)?$this->module->sections:array(),
		array(
			$lang['save'] => 'javascript:doSave();',
			$lang['back'] => 'javascript:doBack();'
		));*/
		$this->sections = array(
			$lang['save'] => 'javascript:doSave();',
			$lang['back'] => 'javascript:doBack();'
		);
	}

	function execute() {
		global $lang;
		if (!method_exists($this->module, 'configure')) echo '<div id="no_config">'.$lang['admin']['errors']['noconfig'].'</div>';
		else $this->module->configure();
	}
}
?>
